package qf.service.serviceImpl;

import qf.dao.UserDao;
import qf.pojo.User;
import qf.service.UserService;
import qf.utils.Constants;
import qf.utils.MD5Utils;

/**
 * @author 86198
 * @version V1.0
 * @Project Java_qf
 * @Package qf.service.serviceImpl
 * @Description:
 * @Date 2022/5/23 15:23
 */
public class UserServiceImpl implements UserService {
    private UserDao userdao;

    public UserServiceImpl(UserDao userdao) {
        this.userdao = userdao;
    }
    @Override
    public User findUsers(String username, String password) {
        User user = userdao.findUsername(username);
        //如果user对象为null直接返回null
        if (user == null) {
            return null;
        }
        String password1 = MD5Utils.md5(password);
        //输入密码与查找到的用户密码是否相同，不相同返回null
        if (!user.getPassword().equals(password1)) {
            return null;
        }

        //判断是否为会员
        if (Constants.ROLE_CUSTOMER ==user.getRole() ) {
            return user;
        }
        return null;
    }

    @Override
    public boolean findUserName(String username) {
        User user = userdao.findUsername(username);
        if (user == null) {
            return false;
        }else{
            return true;
        }
    }

    @Override
    public int registerUser(User user) {
        return userdao.registerUser(user);

    }
}
